package com.xomily.devops.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xomily.common.annotation.Log;
import com.xomily.common.core.controller.BaseController;
import com.xomily.common.core.domain.AjaxResult;
import com.xomily.common.enums.BusinessType;
import com.xomily.devops.domain.DevAlarm;
import com.xomily.devops.service.IDevAlarmService;
import com.xomily.common.utils.poi.ExcelUtil;
import com.xomily.common.core.page.TableDataInfo;

/**
 * 系统告警Controller
 * 
 * @author xomily
 * @date 2021-11-29
 */
@RestController
@RequestMapping("/devops/alarm")
public class DevAlarmController extends BaseController
{
    @Autowired
    private IDevAlarmService devAlarmService;

    /**
     * 查询系统告警列表
     */
    @PreAuthorize("@ss.hasPermi('devops:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevAlarm devAlarm)
    {
        startPage();
        List<DevAlarm> list = devAlarmService.selectDevAlarmList(devAlarm);
        return getDataTable(list);
    }

    /**
     * 导出系统告警列表
     */
    @PreAuthorize("@ss.hasPermi('devops:alarm:export')")
    @Log(title = "系统告警", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DevAlarm devAlarm)
    {
        List<DevAlarm> list = devAlarmService.selectDevAlarmList(devAlarm);
        ExcelUtil<DevAlarm> util = new ExcelUtil<DevAlarm>(DevAlarm.class);
        return util.exportExcel(list, "系统告警数据");
    }

    /**
     * 获取系统告警详细信息
     */
    @PreAuthorize("@ss.hasPermi('devops:alarm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(devAlarmService.selectDevAlarmById(id));
    }

    /**
     * 修改系统告警
     */
    @PreAuthorize("@ss.hasPermi('devops:alarm:edit')")
    @Log(title = "系统告警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevAlarm devAlarm)
    {
        return toAjax(devAlarmService.updateDevAlarm(devAlarm));
    }

    /**
     * 删除系统告警
     */
    @PreAuthorize("@ss.hasPermi('devops:alarm:remove')")
    @Log(title = "系统告警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(devAlarmService.deleteDevAlarmByIds(ids));
    }
}
